package com.oracle.ateam.atg.droplet;

import java.io.IOException;

import javax.servlet.ServletException;

import atg.core.util.StringUtils;
import atg.nucleus.naming.ParameterName;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;
import atg.servlet.DynamoServlet;

/**
 * Test droplet - doesn't really do anything useful. Just for showing how to
 * build an ATG module and using Dust on droplets.
 *
 */
public class SampleDroplet extends DynamoServlet {

	public final static ParameterName EMPTY = ParameterName.getParameterName("empty");
	public final static ParameterName OUTPUT_PARAM = ParameterName.getParameterName("output");
	public final static String OUTPUT_DATA = "outdata";

	@Override
	public void service(final DynamoHttpServletRequest pRequest, final DynamoHttpServletResponse pResponse)
			throws ServletException, IOException {

		final String sessionId = pRequest.getSession().getId();

		if (isLoggingDebug()) {
			logDebug("got sessionId " + sessionId);
		}

		if (!StringUtils.isEmpty(sessionId)) {
			pRequest.setParameter(OUTPUT_DATA, sessionId);
			// Service the output oparam
			pRequest.serviceLocalParameter(OUTPUT_PARAM, pRequest, pResponse);
		} else {
			pRequest.serviceLocalParameter(EMPTY, pRequest, pResponse);
		}
	}

}
